﻿@{
    ViewBag.Title = "Search";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div id="toolbar_wrapper" class="clearfix">

    <h4>搜索</h4>
    <form method="post" action="@Url.Action("Search")">
        <div class="toolbar">
		    <div class="span2">
			    <label>部门:</label>
		    </div>
		    <div class="span2 input-append">
			    <select class="input-mini" id="department" name="department">
                    <option />
                    @foreach (var item in ViewBag.Departments)
                    {
                    <option @if (ViewBag.Department == item) {<text>selected</text>}  value="@item">@item</option>
                    }
                </select>
		    </div>
		    <div class="span2">
			    <label>班组:</label>
		    </div>
		    <div class="span2 input-append">
			    <select class="input-mini" id="team" name="team">
                    <option />
                    @foreach (var item in ViewBag.Teams)
                    {
                    <option @if (ViewBag.Team == item) {<text>selected</text>}  value="@item">@item</option>
                    }
                </select>
		    </div>
		    <div class="span2">
			    <label>工房:</label>
		    </div>
		    <div class="span2 input-append">
			    <select class="input-mini" id="shopFloor" name="shopFloor">
                    <option />
                    @foreach (var item in ViewBag.ShopFloors)
                    {
                    <option @if (ViewBag.ShopName == item.ShopName) {<text>selected</text>} value="@item.ShopName">@item.ShopName</option>
                    }
                </select>
		    </div>
            <div class="span2">
			    <label>起始:</label>
		    </div>
		    <div class="span3 input-append">
			    <input class="span2" type="text" id="from" name="from" value="@ViewBag.From"/>
			    <span class="add-on"><i class="icon-calendar"></i></span>
		    </div>
		    <div class="span2">
			    <label>截止:</label>
		    </div>
		    <div class="span3 input-append">
			    <input class="span2" type="text" id="to" name="to" value="@ViewBag.To"/>
			    <span class="add-on"><i class="icon-calendar"></i></span>
		    </div>
		    <button id="task_search" type="submit" class="btn btn-mini" style="margin-top:4px;"><i class="icon-search"></i></button>
	    </div>
    </form>
</div>

<div id="myGrid">
</div>

@section inlinestyle {
#toolbar_wrapper { background: #ccc; }
#toolbar_wrapper h4 { float: left; line-height: 36px; margin: auto;}
#toolbar_wrapper .btn-group { margin: 3px 5px 0 0; float: right; }
	.toolbar {
		background: #ccc;
		padding-top: 4px;
        float: right;
	}
    .toolbar label {
        text-align: right;
        line-height: 30px;
    }

    .toolbar .span2 { width: 48px; }
    .toolbar .btn { width: 24px; }
}

@section links {
    <link rel="stylesheet" href="~/Content/bootstrap/css/bootstrap.css" />
    <link rel="stylesheet" href="~/Content/font-awesome/css/font-awesome.css" />
    <link rel="stylesheet" href="~/Content/jqueryui/css/jquery-ui.css" />
    <link rel="stylesheet" href="~/Content/timepicker/jquery-ui-timepicker-addon.css" />
    <link rel="stylesheet" href="~/Content/ligerUI/skins/Aqua/css/ligerui-common.css" />
    <link rel="stylesheet" href="~/Content/ligerUI/skins/Aqua/css/ligerui-grid.css" />
}

@section scripts {
	@Scripts.Render("~/bundles/js/jquery_ui_ligerui")
    <script type="text/javascript">

        $(function() {
            // disable cache for ajax 'get' operations
            $.ajaxSetup({ cache: false });

            function msjsonDate(value) {
		        var newdate = new Date(parseInt(value.replace("/Date(", "").replace(")/",""), 10));
		        return $.datepicker.formatDate('yy年mm月dd日', newdate);
            }

	        var grid = $("#myGrid").ligerGrid({
                    columns: [
                        { display: '任务名称', name: 'Name', align: 'left', minWidth: 200, render: function(value) {
                            var result = '<a class="cell" href="@Url.Action("Status", "Task")/' + value.ID;
                    	    if (value.Status === 0) {
                                result += '" title="已完成"> <i class="text-success icon-ok"></i> ' + value.Name;
                            } else if (value.Status === 1) {
                                result += '" title="进行中"> <i class="text-warning icon-play"></i> ' + value.Name;
                            } else {
                                result += '" title="尚未开始"> <i class="text-error icon-stop"></i> ' + value.Name;
                            }

                            result += '</a>';

                            return result;
                        }},
                        { display: '产品名称', name: 'ProductName', align: 'left', minWidth: 200 },
                        { display: '工房', name: 'ShopName' },
                        { display: '起始时间', name: 'StartTime', render: function(value) {
                            return msjsonDate(value.StartTime);
                        }},
                        { display: '截止时间', name: 'EndTime', render: function(value) {
                            return msjsonDate(value.EndTime);
                        }},
                        { display: '主要危险品', name: 'DangerousProducts' },
                        { display: '在制量', name: 'InPopulating' },
                        { display: '危险工序', name: 'DangerousProcedure' },
                        { display: '带班长', name: 'TeamLeader' },
                        { display: '班组联系电话', name: 'TeamTel' }
                    ], 
                    url: "@Url.Action("Search", "ShopFloor")",
                    parms: [{
                        name: 'department',
                        value: $('#department').val()
                    }, {
                        name: 'team',
                        value: $('#team').val()
                    }, {
                        name: 'shopFloor',
                        value: $('#shopFloor').val()
                    }, {
                        name: 'from',
                        value: $('#from').val()
                    }, {
                        name: 'to',
                        value: $('#to').val()
                    }],
                    method: 'get',
                    contentType: 'json',
                    pageSize: 100,
                    width: 926, 
                    height: '99%', 
                    checkbox: false
                });
            $("#pageloading").hide();

            $.datepicker.setDefaults({ // Default regional settings
	            closeText: '完成', // Display text for close link
	            prevText: '向前', // Display text for previous month link
	            nextText: '向后', // Display text for next month link
	            currentText: '今天', // Display text for current month link
	            monthNames: ['一月','二月','三月','四月','五月','六月',
		            '七月','八月','九月','十月','十一月','十二月'], // Names of months for drop-down and formatting
	            monthNamesShort: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'], // For formatting
	            dayNames: ['星期日', '星期二', '星期三', '星期四', '星期五', '星期五', '星期六'], // For formatting
	            dayNamesShort: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'], // For formatting
	            dayNamesMin: ['日','一','二','三','四','五','六'], // Column headings for days starting at Sunday
	            weekHeader: 'Wk', // Column header for week of the year
	            dateFormat: 'yy-mm-dd', // See format options on parseDate
	            firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
	            isRTL: false, // True if right-to-left language, false if left-to-right
	            showMonthAfterYear: false, // True if the year select precedes month, false for month then year
	            yearSuffix: '年' // Additional text to append to the year in the month headers
            });

            $('#from').datetimepicker({ 
            	addSliderAccess: true,
	            sliderAccessArgs: { touchonly: false },
	            onClose: function(dateText, inst) {
		            if ($('#to').val() != '') {
			            var testStartDate = $('#from').datetimepicker('getDate');
			            var testEndDate = $('#to').datetimepicker('getDate');
			            if (testStartDate > testEndDate)
				            $('#to').datetimepicker('setDate', testStartDate);
		            }
		            else {
			            $('#to').val(dateText);
		            }
	            },
	            onSelect: function (selectedDateTime){
		            $('#to').datetimepicker('option', 'minDate', $('#from').datetimepicker('getDate') );
	            }
            });
            $('#to').datetimepicker({ 
            	addSliderAccess: true,
	            sliderAccessArgs: { touchonly: false },
	            onClose: function(dateText, inst) {
		            if ($('#from').val() != '') {
			            var testStartDate = $('#from').datetimepicker('getDate');
			            var testEndDate = $('#to').datetimepicker('getDate');
			            if (testStartDate > testEndDate)
				            $('#from').datetimepicker('setDate', testEndDate);
		            }
		            else {
			            $('#from').val(dateText);
		            }
	            },
	            onSelect: function (selectedDateTime){
		            $('#from').datetimepicker('option', 'maxDate', $('#to').datetimepicker('getDate') );
	            }
            });
        });
    </script>
} @* end section scripts *@